/*================================================================
*   Copyright (C) 2021 IMVS Ltd. All rights reserved.
*   
*   Filename   ：serial.h
*   Creator    ：Chase Wu
*   Create Date：2021/06/07
*   Description：
*
================================================================*/


#ifndef _SERIAL_H
#define _SERIAL_H
#ifdef __cplusplus
extern "C"
{
#endif

enum SERIAL_MODE{
    SERIAL_RECV_MODE,
    SERIAL_SEND_MODE,
    SERIAL_LOOPBACK_MODE,
};

typedef struct serial serial_t;

typedef struct {
    int (*init)(serial_t*);
    int (*release)(serial_t*);

    int (*send)(serial_t*);
    int (*receive)(serial_t*);
}serial_op_t;

struct serial{
    int fd;
    int mode;
    char *dev;
    char sendbuf[8];
    char recvbuf[8];

    serial_op_t* op;
};

int serial_destory(serial_t *serial);
int serial_create(serial_t **pserial, char *dev);

int serial_process(char *dev, int mode);

#ifdef __cplusplus
}
#endif
#endif //SERIAL_H
